package com.pay.cloud.fragment;

import android.app.Activity;

import com.pay.cloud.PayApiCloud;
import com.pay.cloud.cpay.MyCloudPay;
import com.tencent.cloudpay.param.QueryOrderRequest;
import com.tencent.cloudpay.param.QueryOrderResponse;
import com.tencent.cloudpay.param.RefundRequest;
import com.tencent.cloudpay.pojo.Order;

public class RefundIngFragment extends RefundIngAbstract {

    private String orderNo;

    public RefundIngFragment(String orderNo) {
        this.orderNo = orderNo;
    }

    @Override
    public void execute() throws Exception {
        Activity activity = getActivity();
        QueryOrderRequest qoReq = new QueryOrderRequest();
        qoReq.setOut_trade_no(orderNo);
        QueryOrderResponse qoRes = MyCloudPay.getInstance(activity).queryOrder(qoReq);
        Order order = qoRes.getOrder();

        final String refundNo = PayApiCloud.generateOrderNo();

        RefundRequest req = new RefundRequest();
        req.setOut_refund_no(refundNo);
        req.setOut_trade_no(orderNo);
        req.setPay_platform(order.getPay_platform());
        req.setRefund_fee(order.getTotal_fee());
        req.setTotal_fee(order.getTotal_fee());

        MyCloudPay.getInstance(activity).refund(req);
        showRefundSubmit();
    }

}
